package com.itheima03;

import com.itheima02.Student;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/7/15
 */
public class ListTest {
    /**
     *      List集合存储学生对象并遍历
     *          创建一个存储学生对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合。
     */
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student stu1 = new Student("阿良",24);
        Student stu2 = new Student("左右",25);
        Student stu3 = new Student("平安",21);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.toString());
        }
        System.out.println("----------");
        Iterator<Student> it = list.iterator();
        while (it.hasNext()) {
            Student stu = it.next();
            System.out.println(stu.toString());
        }
    }
}
